//
//  MainController.m
//  UMPDemo
//
//  Created by Jonathan Diehl on 01.03.10.
//  Copyright 2010 RWTH. All rights reserved.
//

#import "MainController.h"
#import "UMPView.h"
#import "UMPGraphView.h"


@implementation MainController


# pragma mark init & cleanup

// init view
-(void)awakeFromNib
{
	// start the ump listener
	NSError *error = nil;
	umpListener = [[UMPListener alloc] initWithDelegate:self startImmediately:NO error:&error];
	if(error) {
		[NSApp presentError:error];
	}

	umpView.umpListener = umpListener;
	[umpListener start:&error];
	if(error) {
		[NSApp presentError:error];
	}
}

// cleanup
- (void)dealloc
{
	[umpListener stop:nil];
	[umpListener release];
	[umpView release];
	[super dealloc];
}


# pragma mark UMPListener Delegate

// touches received
- (void)umpListener:(UMPListener *)listener didReceiveTouches:(NSArray *)touches;
{
	umpView.touches = touches;
	if([touches count] > 0) {
		[umpGraphView addTouch:[touches objectAtIndex:0]];
	}
}

// ump was updated
- (void)umpListenerDidUpdate:(UMPListener *)listener;
{
	[umpView setNeedsDisplay:YES];
}

// failed
- (void)umpListenerDidFail:(NSError *)error;
{
	[NSApp presentError:error];
}


@end
